package com.tqz.juc.atomic;

import java.util.concurrent.atomic.AtomicReferenceArray;

/**
 * <p>原子操作对象数据类型
 *
 * @author tianqingzhao
 * @since 2022/2/6 17:34
 */
public class AtomicReferenceArrayTest {
    
    static User[] users = new User[] {new User(1), new User(2)};
    
    static AtomicReferenceArray<User> userAtomicReferenceArray = new AtomicReferenceArray<>(users);
    
    public static void main(String[] args) {
        // 修改之前是1
        System.out.println(userAtomicReferenceArray.get(0).id);
        userAtomicReferenceArray.set(0, new User(3));
        // 修改之后是3
        System.out.println(userAtomicReferenceArray.get(0).id);
    }
    
    static class User {
        
        int id;
        
        public User(int id) {
            this.id = id;
        }
    }
}
